@namespace Microsoft.FluentUI.AspNetCore.Components
@inherits ListComponentBase<TOption>
@typeparam TOption

@if (!String.IsNullOrEmpty(Height))
{
    <style>
        @($"#{Id}::part(listbox) {{ max-height: {Height}; z-index: {ZIndex.ComboboxPopup} }}")
    </style>
}

<CascadingValue Value=@_internalListContext Name="ListContext" TValue="InternalListContext<TOption>" IsFixed=true>
    <FluentInputLabel ForId="@Id" Label="@Label" AriaLabel="@AriaLabel" ChildContent="@LabelTemplate" />
    <fluent-combobox @ref=Element
                     id="@Id"
                     class="@ClassValue"
                     style="@StyleValue"
                     autocomplete="@Autocomplete.ToAttributeValue()"
                     open=@Open
                     current-value=@Value
                     placeholder=@Placeholder
                     position=@Position.ToAttributeValue()
                     disabled=@Disabled
                     appearance="@Appearance.ToAttributeValue()"
                     @onchange="@OnChangedHandlerAsync"
                     @attributes="AdditionalAttributes">        
        @if (OptionTemplate == null || Items == null)
        {
            @GetListOptions(Items)
        }
        else
        {
            foreach (TOption item in Items)
            {
                <FluentOption TOption="TOption"
                                Value="@GetOptionValue(item)"
                                Selected="@GetOptionSelected(item)"
                                Disabled="@(GetOptionDisabled(item) ?? false)"
                                OnSelect="@OnSelectCallback(item)">
                        @OptionTemplate(item)
                </FluentOption>
            }
        }
    </fluent-combobox>
</CascadingValue>
